#define  _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    int lastStoneWeight(vector<int>& stones) {
        priority_queue<int> q;
        for (auto e : stones) q.push(e);
        while (q.size() > 1)
        {
            int n1 = q.top(); q.pop();
            int n2 = q.top(); q.pop();
            int gap = abs(n1 - n2);
            if (gap) q.push(gap);
        }
        return q.empty() ? 0 : q.top();
    }
};